<template>
  <div class="practice">
    <header class="page-header">
      <h1>练习中心</h1>
      <p>通过练习巩固你的数学知识</p>
      <!-- 未登录用户提示 -->
      <div v-if="!userStore.isAuthenticated" class="login-notice">
        <p>💡 当前为预览模式，登录后可体验完整功能</p>
      </div>
    </header>

    <div class="practice-content">
      <div class="practice-categories">
        <h2>练习分类</h2>

        <!-- 学段选择器 -->
        <div class="level-selector">
          <h3>选择学段</h3>
          <div class="level-buttons">
            <button
              v-for="level in levels"
              :key="level.id"
              class="level-btn"
              :class="{ active: selectedLevel === level.id }"
              @click="selectLevel(level.id)"
            >
              {{ level.name }}
            </button>
          </div>
        </div>

        <!-- 搜索和筛选 -->
        <div class="search-filter">
          <div class="search-box">
            <input
              v-model="searchKeyword"
              type="text"
              placeholder="搜索练习分类..."
              class="search-input"
            />
            <span class="search-icon">🔍</span>
          </div>

          <div class="filter-options">
            <select v-model="selectedDifficulty" class="filter-select">
              <option value="">全部难度</option>
              <option value="easy">简单</option>
              <option value="medium">中等</option>
              <option value="hard">困难</option>
            </select>

            <select v-model="sortBy" class="filter-select">
              <option value="name">按名称排序</option>
              <option value="questionCount">按题目数量排序</option>
              <option value="estimatedTime">按时间排序</option>
              <option value="difficulty">按难度排序</option>
            </select>
          </div>
        </div>

        <!-- 练习分类列表 -->
        <div v-if="loading" class="loading">
          <div class="loading-spinner"></div>
          <p>加载中...</p>
        </div>

        <div v-else-if="practiceCategories.length === 0" class="no-categories">
          <p>该学段暂无练习分类</p>
          <!-- <div class="debug-info">
            <p>调试信息：</p>
            <p>当前学段: {{ selectedLevel }}</p>
            <p>数据长度: {{ practiceCategories.length }}</p>
            <p>过滤后长度: {{ filteredPracticeCategories.length }}</p>
          </div> -->
        </div>

        <div v-else class="category-grid">
          <div
            v-for="category in filteredPracticeCategories"
            :key="category.id"
            class="category-card"
            :class="{ active: currentCategory === category.id }"
            @click="selectCategory(category.id)"
          >
            <div class="category-header">
              <div class="category-icon">{{ category.icon }}</div>
              <div class="category-badge" :class="category.difficulty">
                {{ getDifficultyText(category.difficulty) }}
              </div>
            </div>

            <div class="category-content">
              <h3>{{ category.name }}</h3>
              <p class="category-description">{{ category.description }}</p>

              <div class="category-topics">
                <h4>包含知识点：</h4>
                <div class="topics-list">
                  <span
                    v-for="topic in category.topics.slice(0, 3)"
                    :key="topic.id"
                    class="topic-tag"
                  >
                    {{ topic.name }}
                  </span>
                  <span v-if="category.topics.length > 3" class="topic-more">
                    +{{ category.topics.length - 3 }}
                  </span>
                </div>
              </div>
            </div>

            <div class="category-footer">
              <div class="category-stats">
                <div class="stat-item">
                  <span class="stat-icon">📝</span>
                  <span class="stat-value">{{ category.questionCount }}</span>
                  <span class="stat-label">题目</span>
                </div>
                <div class="stat-item">
                  <span class="stat-icon">⏱️</span>
                  <span class="stat-value">{{ category.estimatedTime }}</span>
                  <span class="stat-label">分钟</span>
                </div>
                <div class="stat-item">
                  <span class="stat-icon">🎯</span>
                  <span class="stat-value">{{ category.topics.length }}</span>
                  <span class="stat-label">知识点</span>
                </div>
              </div>

              <!-- 预览标识 -->
              <div v-if="!userStore.isAuthenticated" class="preview-tag">预览</div>

              <!-- 已登录用户显示进度 -->
              <div v-else class="progress-indicator">
                <div class="progress-bar">
                  <div class="progress-fill" :style="{ width: '0%' }"></div>
                </div>
                <span class="progress-text">0%</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 右侧面板 -->
      <div class="right-panel">
        <!-- 未选择分类时显示欢迎信息 -->
        <div v-if="!currentCategory" class="welcome-section">
          <div class="welcome-icon">🎯</div>
          <h2>欢迎来到练习中心</h2>
          <p>选择一个练习分类开始你的练习之旅</p>
          <div v-if="!userStore.isAuthenticated" class="welcome-tip">
            <p>💡 登录后可获得：</p>
            <ul>
              <li>完整的练习题库</li>
              <li>学习进度跟踪</li>
              <li>个性化推荐</li>
              <li>练习历史记录</li>
            </ul>
          </div>
        </div>

        <!-- 选择分类后显示详细信息 -->
        <div v-else class="category-detail">
          <div class="category-detail-header">
            <button @click="() => (currentCategory = '')" class="back-btn">← 返回选择</button>
            <h3>{{ getCurrentCategory?.name }}</h3>
          </div>

          <div class="category-info">
            <div class="category-icon">{{ getCurrentCategory?.icon }}</div>
            <div class="category-meta">
              <span class="difficulty-badge" :class="getCurrentCategory?.difficulty">
                {{ getDifficultyText(getCurrentCategory?.difficulty) }}
              </span>
              <span class="level-badge">{{
                getCurrentCategory?.level === 'primary'
                  ? '小学'
                  : getCurrentCategory?.level === 'junior'
                    ? '初中'
                    : getCurrentCategory?.level === 'senior'
                      ? '高中'
                      : '大学'
              }}</span>
            </div>
          </div>

          <p class="category-description">{{ getCurrentCategory?.description }}</p>

          <!-- 已登录用户显示知识点详情 -->
          <div v-if="userStore.isAuthenticated" class="topics-detail">
            <h4>知识点练习</h4>
            <div class="topics-grid">
              <div v-for="topic in getCurrentCategory?.topics" :key="topic.id" class="topic-card">
                <div class="topic-header">
                  <h5>{{ topic.name }}</h5>
                  <span class="topic-question-count">{{ topic.questionCount }}题</span>
                </div>
                <p class="topic-description">{{ topic.description }}</p>
                <div class="topic-actions">
                  <button @click="startTopicPractice(topic.id)" class="btn btn-primary btn-sm">
                    开始练习
                  </button>
                  <button @click="viewTopicHistory(topic.id)" class="btn btn-secondary btn-sm">
                    查看记录
                  </button>
                </div>
              </div>
            </div>
          </div>

          <!-- 未登录用户显示登录提示 -->
          <div v-else class="login-prompt">
            <div class="login-icon">🔒</div>
            <h4>登录体验完整功能</h4>
            <p>登录后可以查看详细知识点和开始练习</p>
            <button @click="showLoginPrompt = true" class="btn btn-primary">立即登录</button>
          </div>
        </div>
      </div>
    </div>

    <!-- 登录提示弹窗 -->
    <el-dialog
      v-model="showLoginPrompt"
      title="登录体验完整功能"
      width="400px"
      align-center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div class="login-prompt-content">
        <p>请先登录以体验完整的练习功能</p>
        <ul class="feature-list">
          <li>访问完整的练习题库</li>
          <li>保存练习进度</li>
          <li>查看详细的学习报告</li>
          <li>获得个性化推荐</li>
        </ul>
      </div>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeLoginPrompt">取消</el-button>
          <el-button type="primary" @click="goToLogin">去登录</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useUserStore } from '@/stores'
import { useRouter } from 'vue-router'
import { getAllLevels, type Level } from '@/api/subjects'
import { getPracticeCategories, type PracticeCategory } from '@/api/practice'

const userStore = useUserStore()
const router = useRouter()

const currentCategory = ref<string>('')
const selectedLevel = ref<string>('')
const levels = ref<Level[]>([])
const practiceCategories = ref<PracticeCategory[]>([])
const loading = ref(false)
const showLoginPrompt = ref(false)

// 搜索和筛选相关状态
const searchKeyword = ref('')
const selectedDifficulty = ref('')
const sortBy = ref('name')

// 过滤和排序后的练习分类
const filteredPracticeCategories = computed(() => {
  let filtered = practiceCategories.value

  // 按关键词搜索
  if (searchKeyword.value) {
    filtered = filtered.filter(
      (category) =>
        category.name.toLowerCase().includes(searchKeyword.value.toLowerCase()) ||
        category.description.toLowerCase().includes(searchKeyword.value.toLowerCase()),
    )
  }

  // 按难度筛选
  if (selectedDifficulty.value) {
    filtered = filtered.filter((category) => category.difficulty === selectedDifficulty.value)
  }

  // 排序
  filtered = [...filtered].sort((a, b) => {
    switch (sortBy.value) {
      case 'name':
        return a.name.localeCompare(b.name)
      case 'questionCount':
        return b.questionCount - a.questionCount
      case 'estimatedTime':
        return b.estimatedTime - a.estimatedTime
      case 'difficulty':
        const difficultyOrder = { easy: 1, medium: 2, hard: 3 }
        return (
          difficultyOrder[a.difficulty as keyof typeof difficultyOrder] -
          difficultyOrder[b.difficulty as keyof typeof difficultyOrder]
        )
      default:
        return 0
    }
  })

  return filtered
})

// 获取所有学段信息
const fetchLevels = async () => {
  try {
    const response = await getAllLevels()
    levels.value = (response as any).data || []
  } catch (error) {
    console.error('获取学段信息失败:', error)
    levels.value = []
  }
}

// 获取练习分类数据
const fetchPracticeCategories = async (level?: string) => {
  loading.value = true
  try {
    console.log('正在获取练习分类，学段:', level)
    const response = await getPracticeCategories(level ? { level } : undefined)
    console.log('API响应:', response)
    practiceCategories.value = (response as any).data || []
    console.log('练习分类数据:', practiceCategories.value)
  } catch (error) {
    console.error('获取练习分类失败:', error)
    practiceCategories.value = []
  } finally {
    loading.value = false
  }
}

// 选择学段
const selectLevel = (levelId: string) => {
  selectedLevel.value = levelId
  fetchPracticeCategories(levelId)
}

// 获取当前选中的分类信息
const getCurrentCategory = computed(() => {
  return practiceCategories.value.find((c) => c.id === currentCategory.value)
})

// 选择分类
const selectCategory = (categoryId: string) => {
  currentCategory.value = categoryId
}

// 获取难度等级的显示文本
const getDifficultyText = (difficulty: string) => {
  const difficultyMap = {
    easy: '简单',
    medium: '中等',
    hard: '困难',
  }
  return difficultyMap[difficulty as keyof typeof difficultyMap] || difficulty
}

// 开始练习
const startPractice = () => {
  console.log('开始练习:', currentCategory.value)
}

// 查看历史
const viewHistory = () => {
  console.log('查看练习历史')
}

// 开始单个知识点练习
const startTopicPractice = (topicId: string) => {
  console.log('开始单个知识点练习:', topicId)
}

// 查看单个知识点历史
const viewTopicHistory = (topicId: string) => {
  console.log('查看单个知识点历史:', topicId)
}

// 登录提示相关
const closeLoginPrompt = () => {
  showLoginPrompt.value = false
}

const goToLogin = () => {
  router.push('/login?redirect=' + encodeURIComponent(window.location.pathname))
}

// 组件挂载后的初始化逻辑
onMounted(async () => {
  console.log('PracticeView 组件挂载')

  // 测试API连接
  try {
    console.log('测试API连接...')
    const testResponse = await getPracticeCategories()
    console.log('API连接测试成功:', testResponse)
  } catch (error) {
    console.error('API连接测试失败:', error)
  }

  await fetchLevels()
  // 默认选择小学学段
  if (levels.value.length > 0) {
    selectedLevel.value = levels.value[0].id
    await fetchPracticeCategories(selectedLevel.value)
  }
})
</script>

<style scoped>
.practice {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  /* 移除固定高度，让内容自然撑开 */
}

.page-header {
  text-align: center;
  margin-bottom: 40px;
}

.page-header h1 {
  font-size: 2.5rem;
  color: #333;
  margin-bottom: 8px;
}

.page-header p {
  font-size: 1.1rem;
  color: #666;
}

.practice-content {
  display: grid;
  grid-template-columns: 2fr 1fr; /* 改为2:1比例，左侧占更多空间 */
  gap: 32px;
  min-height: 600px;
}

.practice-categories {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.practice-categories h2 {
  margin-bottom: 24px;
  color: #333;
}

/* 学段选择器样式 */
.level-selector {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e9ecef;
}

.level-selector h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: #555;
}

.level-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.level-btn {
  padding: 8px 16px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: white;
  color: #666;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
}

.level-btn:hover {
  border-color: #2196f3;
  color: #2196f3;
}

.level-btn.active {
  background: #2196f3;
  border-color: #2196f3;
  color: white;
}

.loading {
  text-align: center;
  padding: 40px 20px;
  color: #666;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #2196f3;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.no-categories {
  text-align: center;
  padding: 40px 20px;
  color: #666;
  font-style: italic;
}

.debug-info {
  margin-top: 20px;
  padding: 15px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  text-align: left;
  font-family: monospace;
  font-size: 0.9rem;
}

.debug-info p {
  margin: 5px 0;
  color: #666;
}

.category-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  max-height: 600px;
  overflow-y: auto;
  padding: 10px 8px;
}

.category-grid::-webkit-scrollbar {
  width: 6px;
}

.category-grid::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.category-grid::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.category-grid::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.category-card {
  padding: 20px;
  border-radius: 8px;
  background: #f8f9fa;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.category-card:hover {
  background: #e3f2fd;
  border-color: #2196f3;
  transform: translateY(-2px);
}

.category-card.active {
  border-color: #2196f3;
  box-shadow: 0 4px 8px rgba(33, 150, 243, 0.2);
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.category-icon {
  font-size: 2rem;
  color: #2196f3;
}

.category-badge {
  background-color: #e0e0e0;
  color: #333;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
  white-space: nowrap;
}

.category-badge.easy {
  background-color: #e8f5e9;
  color: #2e7d32;
}

.category-badge.medium {
  background-color: #fff3e0;
  color: #ef6c00;
}

.category-badge.hard {
  background-color: #ffebee;
  color: #c62828;
}

.category-content {
  margin-bottom: 12px;
}

.category-content h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
  color: #333;
}

.category-description {
  font-size: 0.9rem;
  color: #666;
  line-height: 1.4;
  margin-bottom: 12px;
}

.category-topics {
  margin-top: 12px;
}

.category-topics h4 {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 8px;
}

.topics-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.topic-tag {
  background-color: #e0e0e0;
  color: #333;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
  white-space: nowrap;
}

.topic-more {
  background-color: #f0f0f0;
  color: #666;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
  white-space: nowrap;
}

.category-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e9ecef;
}

.category-stats {
  display: flex;
  gap: 16px;
  align-items: center;
}

.stat-item {
  text-align: center;
}

.stat-icon {
  font-size: 1.2rem;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: bold;
  color: #2196f3;
  display: block;
}

.stat-label {
  font-size: 0.75rem;
  color: #888;
}

.progress-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-bar {
  width: 100px;
  height: 8px;
  background-color: #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background-color: #4caf50;
  border-radius: 4px;
  transition: width 0.3s ease-in-out;
}

.progress-text {
  font-size: 0.9rem;
  color: #666;
}

.practice-area {
  background: white;
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.practice-session h2 {
  margin-bottom: 16px;
  color: #333;
}

.practice-session p {
  margin-bottom: 24px;
  color: #666;
  line-height: 1.6;
}

.practice-controls {
  display: flex;
  gap: 16px;
  margin-bottom: 32px;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary {
  background: #4caf50;
  color: white;
}

.btn-primary:hover {
  background: #45a049;
  transform: translateY(-2px);
}

.btn-secondary {
  background: #f8f9fa;
  color: #333;
  border: 2px solid #e9ecef;
}

.btn-secondary:hover {
  background: #e9ecef;
}

.practice-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.stat-card {
  text-align: center;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
}

.stat-number {
  font-size: 2rem;
  font-weight: bold;
  color: #2196f3;
  margin-bottom: 8px;
}

.stat-label {
  font-size: 0.9rem;
  color: #666;
}

.welcome-practice {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.welcome-card {
  text-align: center;
  max-width: 400px;
}

.welcome-icon {
  font-size: 4rem;
  margin-bottom: 20px;
}

.welcome-card h2 {
  margin-bottom: 16px;
  color: #333;
}

.welcome-card p {
  color: #666;
  line-height: 1.6;
}

.welcome-tip {
  margin-top: 20px;
  padding: 15px;
  background: #f0f9eb;
  border: 1px solid #e1f3d8;
  border-radius: 8px;
  color: #67c23a;
  font-size: 0.9rem;
}

.welcome-tip ul {
  list-style: none;
  padding: 0;
  margin-top: 10px;
}

.welcome-tip li {
  margin-bottom: 5px;
}

.preview-tag {
  background-color: #ff9800;
  color: white;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: bold;
  margin-top: 10px;
  display: inline-block;
}

.preview-content {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 10px;
  padding: 20px;
  margin-top: 20px;
  margin-bottom: 20px;
}

.preview-demo {
  margin-bottom: 20px;
}

.preview-demo h3 {
  margin-bottom: 15px;
  color: #333;
}

.demo-question {
  margin-bottom: 15px;
}

.demo-question p {
  margin-bottom: 10px;
}

.demo-number-line {
  position: relative;
  height: 30px;
  margin-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.line {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  background-color: #ccc;
  transform: translateY(-50%);
}

.tick {
  position: absolute;
  top: 0;
  left: 0;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: #888;
}

.tick-label {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: #888;
}

.demo-point {
  position: absolute;
  top: 50%;
  left: 33.33%; /* 33.33% of line height */
  transform: translate(-50%, -50%);
  font-size: 1.5rem; /* Larger point */
  color: #2196f3;
}

.demo-answer {
  margin-top: 15px;
  font-size: 0.9rem;
  color: #555;
  line-height: 1.5;
}

.demo-topics {
  margin-top: 15px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e9ecef;
}

.demo-topics h4 {
  margin-bottom: 10px;
  color: #333;
  font-size: 0.9rem;
}

.demo-topics ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.demo-topics li {
  padding: 5px 0;
  color: #666;
  font-size: 0.85rem;
  border-bottom: 1px solid #f0f0f0;
}

.demo-topics li:last-child {
  border-bottom: none;
}

.preview-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

.login-notice {
  background-color: #fff3cd;
  color: #856404;
  padding: 10px 15px;
  border: 1px solid #ffeeba;
  border-radius: 8px;
  margin-top: 20px;
  font-size: 0.9rem;
  font-weight: 600;
}

/* Element Plus 弹窗样式 */
.login-prompt-content {
  text-align: center;
}

.feature-list {
  list-style: none;
  padding: 0;
  margin: 20px 0;
  text-align: left;
}

.feature-list li {
  padding: 8px 0;
  color: #666;
  position: relative;
  padding-left: 20px;
}

.feature-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: #67c23a;
  font-weight: bold;
}

.dialog-footer {
  text-align: center;
}

.category-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.back-btn {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #f8f9fa;
  color: #333;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
}

.back-btn:hover {
  background: #e9ecef;
  border-color: #ccc;
}

.topics-detail {
  margin-bottom: 32px;
}

.topics-detail h3 {
  margin-bottom: 16px;
  color: #333;
}

.topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.topic-card {
  padding: 20px;
  border-radius: 8px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  transition: all 0.3s ease;
}

.topic-card:hover {
  background: #e3f2fd;
  border-color: #2196f3;
  transform: translateY(-2px);
}

.topic-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.topic-header h4 {
  font-size: 1.1rem;
  color: #333;
  margin-bottom: 4px;
}

.topic-question-count {
  background-color: #e0e0e0;
  color: #333;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: bold;
  white-space: nowrap;
}

.topic-description {
  font-size: 0.9rem;
  color: #666;
  line-height: 1.4;
  margin-bottom: 12px;
}

.topic-actions {
  display: flex;
  gap: 8px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* 搜索和筛选样式 */
.search-filter {
  display: flex;
  gap: 15px;
  margin-bottom: 24px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e9ecef;
}

.search-box {
  position: relative;
  flex-grow: 1;
}

.search-input {
  width: 100%;
  padding: 10px 40px 10px 15px;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  font-size: 0.9rem;
  color: #333;
  transition: all 0.3s ease;
}

.search-input:focus {
  border-color: #2196f3;
  box-shadow: 0 0 5px rgba(33, 150, 243, 0.2);
  outline: none;
}

.search-icon {
  position: absolute;
  top: 50%;
  right: 15px;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: #888;
}

.filter-options {
  display: flex;
  gap: 10px;
  align-items: center;
}

.filter-select {
  padding: 8px 12px;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  font-size: 0.9rem;
  color: #333;
  background: white;
  cursor: pointer;
  transition: all 0.3s ease;
}

.filter-select:focus {
  border-color: #2196f3;
  box-shadow: 0 0 5px rgba(33, 150, 243, 0.2);
  outline: none;
}

.right-panel {
  background: #f8f9fa;
  border-radius: 16px;
  padding: 24px;
  height: fit-content;
  position: sticky;
  top: 20px;
}

.welcome-section {
  text-align: center;
  padding: 40px 20px;
}

.welcome-icon {
  font-size: 4rem;
  margin-bottom: 20px;
}

.welcome-section h2 {
  font-size: 1.8rem;
  color: #333;
  margin-bottom: 12px;
}

.welcome-section p {
  color: #666;
  font-size: 1.1rem;
  margin-bottom: 24px;
}

.welcome-tip {
  text-align: left;
  background: white;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #e9ecef;
}

.welcome-tip p {
  color: #333;
  font-weight: 600;
  margin-bottom: 12px;
}

.welcome-tip ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.welcome-tip li {
  color: #666;
  padding: 4px 0;
  position: relative;
  padding-left: 20px;
}

.welcome-tip li::before {
  content: '✓';
  color: #4caf50;
  position: absolute;
  left: 0;
  font-weight: bold;
}

.category-detail {
  text-align: left;
}

.category-detail-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.back-btn {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
  transition: all 0.2s;
  margin-right: 12px;
}

.back-btn:hover {
  background: #e9ecef;
  color: #333;
}

.category-detail-header h3 {
  margin: 0;
  color: #333;
  font-size: 1.4rem;
}

.category-info {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}

.category-icon {
  font-size: 2rem;
  margin-right: 16px;
}

.category-meta {
  display: flex;
  gap: 8px;
}

.difficulty-badge {
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.difficulty-badge.easy {
  background: #d4edda;
  color: #155724;
}

.difficulty-badge.medium {
  background: #fff3cd;
  color: #856404;
}

.difficulty-badge.hard {
  background: #f8d7da;
  color: #721c24;
}

.level-badge {
  padding: 4px 8px;
  background: #e3f2fd;
  color: #1976d2;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.category-description {
  color: #666;
  margin-bottom: 24px;
  line-height: 1.6;
}

.topics-detail h4 {
  color: #333;
  margin-bottom: 16px;
  font-size: 1.2rem;
}

.topics-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topic-card {
  background: white;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid #e9ecef;
}

.topic-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.topic-header h5 {
  margin: 0;
  color: #333;
  font-size: 1rem;
}

.topic-question-count {
  background: #f8f9fa;
  color: #666;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 0.8rem;
}

.topic-description {
  color: #666;
  font-size: 0.9rem;
  margin-bottom: 12px;
  line-height: 1.4;
}

.topic-actions {
  display: flex;
  gap: 8px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.login-prompt {
  text-align: center;
  padding: 24px 16px;
}

.login-icon {
  font-size: 2rem;
  margin-bottom: 16px;
}

.login-prompt h4 {
  color: #333;
  margin-bottom: 8px;
}

.login-prompt p {
  color: #666;
  margin-bottom: 20px;
}

@media (max-width: 768px) {
  .practice-content {
    grid-template-columns: 1fr;
  }

  .category-grid {
    grid-template-columns: 1fr;
  }

  .practice-stats {
    grid-template-columns: 1fr;
  }

  .search-filter {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-options {
    flex-direction: column;
    align-items: stretch;
  }
}
</style>
